<!--
 * @Author: 黄宇/Hyuishine
 * @Date: 2022-05-16 11:14:09
 * @LastEditors: 黄宇/Hyuishine
 * @LastEditTime: 2024-05-16 09:54:28
 * @Description: 
 * @Email: hyuishine@gmail.com
 * @Company: 3xData
 * @youWant: 服务机构-详情信息 表单
-->
<template>
  <view class="container_page">
    <!-- 顶部自定义导航栏 -->
    <action-bar :options="navOptions" />

    <!-- 单位基本信息 -->
    <base-info ref="baseInfo" :form="form" />
    <work-place :form="form" />
    <fire-equipment :agencyId="agencyId" />
    <staff-info :list="list" :people1="people1" :people2="people2" />
    <quality-manage :form="form" />
    <service-capabilities :form="form" />
    <au-dit ref="audit" :form="form"></au-dit>
    <view style="height: 100rpx"></view>
    <view class="btn_box" v-if="state == '1'">
      <button class="btn_audit" :disabled="disabled" @click="auditClick">审核</button>
    </view>
  </view>
</template>
<script>
import BaseInfo from "./foldForm/baseInfo.vue";
import WorkPlace from "./foldForm/workPlace.vue";
import FireEquipment from "./foldForm/fireEquipment.vue";
import StaffInfo from "./foldForm/staffInfo.vue";
import QualityManage from "./foldForm/qualityManage.vue";
import ServiceCapabilities from "./foldForm/serviceCapabilities.vue";
import AuDit from "./foldForm/audit.vue"

export default {
  components: {
    BaseInfo,
    WorkPlace,
    FireEquipment,
    StaffInfo,
    QualityManage,
    ServiceCapabilities,
    AuDit
  },
  data() {
    return {
      // 导航栏参数
      navOptions: {
        left: {
          icon: "back",
        },
        center: {
          title: "机构信息",
        },
      },
      form: {},
      agencyId: "",
      people1: 0,
      people2: 0,
      list: [],
      disabled: false,
      state: null,
      loading: false,
    };
  },
  onLoad(e) {
    this.agencyId = e.id;
    this.state = e.state
    this.getAgency();
  },
  created() { },
  methods: {
    getAgency() {
      if (this.loading) return

      this.loading = true
      uni.showLoading({
        title: '正在加载请稍后',
        mask: true
      });

      this.$store
        .dispatch("organizeInfo_form", this.agencyId)
        .then(({ data }) => {
          this.form = data;
          this.list = data.dstaffInfoList
          data.dstaffInfoList.forEach((item) => {
            if (item.registeredFireEngineer) {
              this.people1 += 1;
            }
            if (item.facilityOperators) {
              this.people2 += 1;
            }
          });
          this.$refs.baseInfo.getServerType()
        })
        .finally(() => {
          let timer = setTimeout(() => {
            this.loading = false
            uni.hideLoading();
            clearTimeout(timer)
          }, 3000);
        })
    },

    auditClick() {
      let that = this
      let data = this.$refs.audit
      this.disabled = true
      if (!data.auditState) {
        uni.showToast({
          title: '请选择审核结果',
          duration: 1500,
          icon: 'none'
        });
        that.disabled = false
        return
      }
      if (data.auditState == '0' && !data.auditShowMessage) {
        uni.showToast({
          title: '请输入审核意见',
          duration: 1500,
          icon: 'none'
        });
        that.disabled = false
        return
      }
      let dist = {
        agencyId: that.agencyId,
        result: data.auditState,
        message: data.auditShowMessage
      }
      this.$store.dispatch('get_audit', dist).then(res => {
        if (res.code == 200) {
          uni.showToast({
            title: '审核成功',
            duration: 1500,
            icon: 'none'
          });
          setTimeout(() => {
            that.disabled = false
            uni.navigateBack({
              delta: 1
            });
          }, 1500);
        } else {
          uni.showToast({
            title: '操作失败',
            duration: 1500,
            icon: 'none'
          });
          that.disabled = false
        }
      })
    }
  },
};
</script>
<style lang="scss" scoped>
@import "./styles/foldForm.scss";

.btn_box {
  width: 100%;
  height: 100rpx;
  position: fixed;
  bottom: 0;
  background-color: #fff;
  border-top: 1rpx solid #e5e5e5;
  display: flex;
  align-items: center;
  justify-content: center;

  .btn_audit {
    width: 710rpx;
    height: 80rpx;
    line-height: 80rpx;
    text-align: center;
    font-size: 28rpx;
    color: #fff;
    background: $OVERALL_CONFIRM_BUTTON_COLOR;
  }
}
</style>
